/**
 * nghilt
 * 2011/09/16
 *
 * Copyright by N&N.,Inc
 */
package vn.nnn.shogi.quanco;

import java.awt.Point;
import java.awt.Rectangle;
import java.util.ArrayList;

import javax.swing.JApplet;

import at.com.vn.chess.util.RectangleUtils;

import vn.nnn.shogi.board.Board;

/**
 * 
 */
public class QuanTuongVang extends QuanCo {

	public QuanTuongVang(Rectangle toaDo, int color, boolean normalDirection,
			JApplet mainApplet) {
		super(toaDo, color, normalDirection, mainApplet);
	}

	@Override
	public void setToaDoNhaTu() {
		toaDoNhaTu = new Point(1, 0);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see vn.nnn.shogi.quanco.QuanCo#canMove(java.awt.Rectangle,
	 * vn.nnn.shogi.quanco.QuanCo, java.util.ArrayList)
	 */
	@Override
	public boolean canMove(Board board, Rectangle destination,
			QuanCo foundedPiece, ArrayList<QuanCo> listQuanCo) {
		boolean canmove = false;

		Rectangle quanThap = toaDo;
		Rectangle quanCao = destination;

		if (normalDirection) {
			if (color == QUAN_DEN) {
				quanThap = destination;
				quanCao = toaDo;
			}
		} else {
			if (color == QUAN_TRANG) {
				quanThap = destination;
				quanCao = toaDo;
			}
		}

		// Neu dung nguyen tai cho thi khong tinh la mot luot di chuyen
		if (toaDo == destination) {
			return false;
		}

		// Neu cung hang hoac la mot hang o phia tren
		if (RectangleUtils.isNextRow(quanThap, quanCao)
				|| RectangleUtils.isInSameRow(quanThap, quanCao)) {

			// Neu cung cot hoac la 2 cot o ben canh
			if (RectangleUtils.isInSameColumn(quanThap, quanCao)
					|| RectangleUtils.isColumnBeside(quanThap, quanCao)) {
				canmove = true;
			}
		}

		// Neu la hang phia sau va cung mot cot
		else if (RectangleUtils.isNextRow(quanCao, quanThap)
				&& RectangleUtils.isInSameColumn(quanThap, quanCao)) {
			canmove = true;
		}

		// Dieu kien co ban khi di quan
		if (canmove) {
			canmove = isPassToBasicMoveCondition(board, destination,
					foundedPiece, listQuanCo);
		}

		return canmove;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see vn.nnn.shogi.quanco.QuanCo#canRelease(vn.nnn.shogi.quanco.Board,
	 * java.awt.Rectangle, java.util.ArrayList)
	 */
	@Override
	public boolean canRelease(Board board, Rectangle destination,
			ArrayList<QuanCo> listQuanCo) {

		return isPassToBasicReleaseCondition(board, destination, listQuanCo);
	}

	/*
	 * (non-Javadoc) Tuong vang khong the phong cap
	 * 
	 * @see vn.nnn.shogi.quanco.QuanCo#canUpgrade()
	 */
	@Override
	public boolean canUpgrade() {
		return false;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see vn.nnn.shogi.quanco.QuanCo#upgrade(java.awt.Rectangle,
	 * java.util.ArrayList) 
	 * Quan tuong vang khong the phong cap
	 */
	@Override
	public void upgrade(Rectangle destination, ArrayList<QuanCo> listQuanCo) {

	}
}
